//验证配置json文件是否有重复数据
export function verificationRepeat(verificationList) {
  if (verificationList instanceof Array) {
    //校验json文件中，id和Name是否包含重复项
    const ids = verificationList.map(value => value.id)
    const idsSet = new Set(ids)
    const names = verificationList.map(v => v.name)
    const nameSet = new Set(names)
    if (idsSet.size == verificationList.length && nameSet.size == verificationList.length) {
      return true
    }
    return false

  }
  return false

}

//验证是否超出抽奖数量
export function verificationIsRepeatNumber(priceNumber, personList, priceType) {
  let str = ''
  if (!priceType) {
    str = `奖品等级未导入！请检查`
    return str
  }
  if (!priceNumber) {
    str = `${priceType}奖品数量未导入!请检查`
    return str
  }
  if (personList.length === 0) {
    str = `${priceType}中奖人员名单为空！请检查`
    return str
  }

  if (personList.length != +priceNumber) {
    str = `${priceType}中奖人数为${priceNumber}人，抽中人数为${personList.length}人，请检查！`
    return str
  }
  return str
}

//验证抽出的奖品是否超出规定的数量
export function verificationIsRepeatPerson(priceTotleNumber,...priceList){
  if(priceTotleNumber === 0){
    return `调用方法请传入奖品数量`
  }
  //利用剩余参数，把中奖人数和奖品数进行比较判断
  
  let res = new Set(priceList.flat(Infinity))
  if(res.size != priceTotleNumber){
    return `当前中奖人数和当前奖品数量不相等，请检查`
  }
  return ''
}

//是否存在重复抽奖人员
export function verificationIsRepeat(...priceList){
  let arr = priceList.flat(Infinity)
    var tmp = [];
    if (Array.isArray(arr)) {
      arr
      .concat()
      .sort()
      .sort(function (a, b) {
        if (a == b && tmp.indexOf(a) === -1) { tmp.push(a) }
      })
  }
  return tmp.join()
}